package com.lu.pojo.thread;

/**
 * @author luzhenfang
 * @date 2020 06 05
 * @description 多线程模拟火车售票窗口
 */

public class TestTicketWindow {
    private static Integer ticket = 50;

    public static void main(String[] args) {
        // 售票窗口
        new Thread(TestTicketWindow::sale, "窗口一").start();
        new Thread(TestTicketWindow::sale, "窗口二").start();
        new Thread(TestTicketWindow::sale, "窗口三").start();
        new Thread(TestTicketWindow::sale, "窗口四").start();

    }

    // 售票
    public static void sale() {
        while (true) {
            if (ticket != 0) {
                System.out.println(Thread.currentThread().getName() + ":售出一张,剩余:" + --ticket);
            } else {
                break;
            }
        }
        System.out.println("已售空,余票:"+ticket);
    }
}
